package com.project.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.project.bean.ClientBean;
import com.project.mapper.IClientMapper;
import com.project.service.IClientService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;


@Service
@Transactional
public class ClientServiceImpl implements IClientService {

    @Autowired
    private IClientMapper mapper;

    @Override
    public IPage<ClientBean> findByItem(Integer pageNO, String name, String scope) {
        QueryWrapper<ClientBean> qw = new QueryWrapper<>();
        if (name !=null && name.length()!=0){
            qw.like("c_name",name);
        }
        if (scope !=null && scope.length()!=0){
            qw.like("c_scope",scope);
        }
        return mapper.selectPage(new Page(pageNO,3),qw);
    }

    @Override
    public ClientBean findById(Integer clientId) {
        return mapper.selectById(clientId);
    }

    @Override
    public void update(Integer clientId, String person, String phone, String scope) {
        ClientBean clientBean = mapper.selectById(clientId);
        clientBean.setUser(person);
        clientBean.setPhone(phone);
        clientBean.setScope(scope);
        mapper.updateById(clientBean);
    }

    @Override
    public void add(ClientBean client) {
        mapper.insert(client);
    }

    @Override
    public List<ClientBean> findAll() {
        return mapper.findAll();
    }
}
